﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using Yipusoft.Common.BLL;
using Yipusoft.Common.Model;
using Yipusoft.Task.BLL;
using Yipusoft.Task.Model;
using System.Collections.Generic;
using System.Text;
using Dundas.Charting.WebControl;

public partial class Task_ViewTask : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            BindData();
        }
    }
    private void BindData()
    {
        string[] CnNums = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三" };
        StringBuilder sb = new StringBuilder();
        List<TaskInfo> tasks = Task.GetTasks(int.Parse(Request.QueryString["RootId"]));
        sb.Append("<div class=title>" + tasks[0].Title + "</div>");
        sb.Append("<div class=date>[" + tasks[0].StartDate.ToShortDateString() + "—" + tasks[0].EndDate.ToShortDateString() + "] ");

        if (tasks[0].CreateDepartment.Substring(0, 4) != "1300")
        {
            Response.Redirect("ViewTaskDaZhongD.aspx?RootId=" + Request["RootId"] + "");
        }

        sb.Append(Department.GetDepartment(tasks[0].CreateDepartment).FullName + " ");
        sb.Append(tasks[0].CreateUser);
   
        if (tasks[0].Child == 0)
        {
            sb.Append("&nbsp;&nbsp;迟报扣分：" + tasks[0].LatePoints);
        }
        sb.Append("</div>");
        if (tasks[0].Comment != "")
        {
            sb.Append("<div class=comment>" + UserFun.TextToHtml(tasks[0].Comment) + "</div>");
        }

        //显示附件
        if (tasks[0].Files.Count > 0)
        {
            foreach (TaskFileInfo file in tasks[0].Files)
            {
                sb.Append("<div class=file><img src=../images/attachment.gif alt=> <a href=../Upload" + file.FileName + " target=_blank>" + file.FileTitle + "</a></div>");
            }
        }
        int j = 0;
        int k = 1;
        for (int i = 1; i < tasks.Count; i++)
        {
            TaskInfo task = tasks[i];
            if (task.Depth == 1)
            {
                sb.Append("<div class=subtitle>");
                sb.Append("第" + CnNums[j] + "阶段、");
                j++;
                k = 1;
            }
            else
            {
                sb.Append("<div class=thtitle>");
                sb.Append(k.ToString() + "、");
                k++;
            }
            sb.Append(task.Title + "[" + task.StartDate.ToString("MM-dd") + "—" + task.EndDate.ToString("MM-dd") + "]");

            sb.Append("&nbsp;&nbsp;迟报扣分：" + tasks[0].LatePoints);
            sb.Append("</div>");

            if (task.Comment != "")
            {
                sb.Append("<div class=comment>" + UserFun.TextToHtml(task.Comment) + "</div>");
            }
            //显示附件
            if (task.Files.Count > 0)
            {
                foreach (TaskFileInfo file in task.Files)
                {
                    sb.Append("<div class=file><img src=../images/attachment.gif alt=> <a href=../Upload" + file.FileName + " target=_blank>" + file.FileTitle + "</a></div>");
                }
            }
        }

        Body.Text = sb.ToString();

        DataView dv = SplitPage.GetPageData("select userid, shortname, progress from view_taskusers2 where taskid='" + Request.QueryString["RootId"] + "' order by userid", 0, 1000);
        UserChart.Series["完成进度(%)"].Points.DataBindXY(dv, "ShortName", dv, "Progress");
        for (int x = 0; x < UserChart.Series[0].Points.Count; x++)
        {
            if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "100102") || Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID.Substring(0, 4) == dv[x]["UserId"].ToString().Substring(0, 4))
            {

                UserChart.Series[0].Points[x].Href = "ViewUserTask.aspx?RootId=" + Request.QueryString["RootId"] + "&UserId=" + dv[x]["UserId"].ToString();
            }
        }
    }
    public string GetUserName(string userId)
    {
        return Department.GetDepartment(userId).ShortName;
    }
}
